package com.spc.car.web.controller.log;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spc.car.core.framework.web.domain.AjaxResult;
import com.spc.car.data.domain.log.po.ProjectOperationQueryPO;
import com.spc.car.data.entity.log.LogProjectOperation;
import com.spc.car.data.service.log.LogProjectOperationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

@Validated
@RequestMapping("/log")
@Api(tags = "日志")
@RestController
public class LogProjectController {

    @Autowired
    private LogProjectOperationService logProjectOperationService;


    @ApiOperation(value = "查询项目操作日志", notes = "查询项目操作日志")
    @PostMapping("/listProjectOperation")
    public AjaxResult listProjectOperation(@RequestBody(required = false) ProjectOperationQueryPO queryPO) {

        QueryWrapper<LogProjectOperation> condition = new QueryWrapper<>();
        Page page = new Page(0, 10);
        if (Objects.nonNull(queryPO)) {
            condition = (QueryWrapper)queryPO.toWrapper();
            page = new Page(ObjectUtils.defaultIfNull(queryPO.getPage(), 0),
                    ObjectUtils.defaultIfNull(queryPO.getPageSize(), 10));
        }

        return AjaxResult.success("查询项目日志成功",
                logProjectOperationService.page(page, condition));

    }
}
